package com.pixelengine.Task26Oee;

public class FilenameReplacer {
    public static String[] token = new String[]{"{YYYY}","{YYYYMMDD}","{MM}","{DD}","{HH}","{mm}","{ss}"};
    public static String replace(String template,String dt14) {
        String[] reps = new String[token.length] ;
        reps[0] = dt14.substring(0,4);
        reps[1] = dt14.substring(0,8) ;
        reps[2] = dt14.substring(4,6) ;
        reps[3] = dt14.substring(6,8) ;
        reps[4] = dt14.substring(8,10) ;
        reps[5] = dt14.substring(10,12) ;
        reps[6] = dt14.substring(12,14) ;
        String res = template ;
        for(int i=0;i<token.length;++i) {
            res = res.replace(token[i], reps[i]) ;
        }
        return res ;
    }

    //add {EXTRA}
    public static String replace2(String template,String dt14,String extra) {
        String[] reps = new String[token.length] ;
        reps[0] = dt14.substring(0,4);
        reps[1] = dt14.substring(0,8) ;
        reps[2] = dt14.substring(4,6) ;
        reps[3] = dt14.substring(6,8) ;
        reps[4] = dt14.substring(8,10) ;
        reps[5] = dt14.substring(10,12) ;
        reps[6] = dt14.substring(12,14) ;
        String res = template ;
        for(int i=0;i<token.length;++i) {
            res = res.replace(token[i], reps[i]) ;
        }
        res = res.replace("{EXTRA}", extra) ;
        return res ;
    }
}
